package com.sitc.street_lab_2013;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class SplashScreen extends Activity {

	private final int SPLASH_DISPLAY_LENGTH = 3000;
	
	private SharedPreferences sharedPref;
    private SharedPreferences.Editor prefEditor;
	
	private ImageView logoImageView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.splash_screen_layout);
        
        sharedPref = getSharedPreferences("sitc",MODE_PRIVATE);
        prefEditor = sharedPref.edit();

        /* New Handler to start the Menu-Activity 
         * and close this Splash-Screen after some seconds.*/
        new Handler().postDelayed(new Runnable(){
            @Override
            public void run() {
               createNextIntent();
            }
        }, SPLASH_DISPLAY_LENGTH);
        
        setLogoImageViewListener();
    }

	private void setLogoImageViewListener() {
		
		logoImageView = (ImageView) findViewById(R.id.LogoImageView);
		logoImageView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				createNextIntent();
			} 
			
		});
	}
	
	private void createNextIntent() {
		
		/* Create an Intent that will start the Menu-Activity. */
        Intent mainIntent;
		 
		if(isFirstStart())
		{
			mainIntent= new Intent(SplashScreen.this,HelpActivity.class);
			prefEditor.putBoolean("firstStart", false);
			prefEditor.commit();
		} else {
			mainIntent= new Intent(SplashScreen.this,HomeListViewActivity.class);
		}
        
        SplashScreen.this.startActivity(mainIntent);
        SplashScreen.this.finish();
	}

	private boolean isFirstStart() {
        
        return sharedPref.getBoolean("firstStart", true);
	}
}